package helper.request.usermgmt;

import java.sql.SQLException;

import server.dbconnector.DatabaseConnector;
import base.User;

public class ModifyUserDetailsRequest implements helper.request.RequestAfterLogin{
	private static final long serialVersionUID = 9023355921440218049L;
	private User targetuser;
	public ModifyUserDetailsRequest(User target,String realnameA,String emailA,String phoneA,int Sex){
		this.setTargetuser(target);
		target.setrealname(realnameA);
		target.setemail(emailA);
		target.setphonenumber(phoneA);
		target.setsex(Sex);
	}
	public void setemail(String email){
		this.getTargetuser().setemail(email);
	}
	public void setsex(int sex){
		this.getTargetuser().setsex(sex);
	}
	public void setphone(String phone){
		this.getTargetuser().setphonenumber(phone);
	}
	public void setrealname(String name){
		this.getTargetuser().setrealname(name);
	}
	
	@Override
	public User getcurrentuser() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int getcurrentuserid() {
		// TODO Auto-generated method stub
		return 0;
	}

	public void setTargetuser(User targetuser) {
		this.targetuser = targetuser;
	}
	public User getTargetuser() {
		return targetuser;
	}
	@Override
	public boolean execute() {
		// TODO Auto-generated method stub
		return false;
	}
	@Override
	public void process(DatabaseConnector dc)throws SQLException{
		dc.commit("update user set password='"+this.getTargetuser().getpassword()+"' where ID="+this.getTargetuser().getid());
		dc.commit("update user set email='"+this.getTargetuser().getemail()+"' where ID="+this.getTargetuser().getid());
		dc.commit("update user set phonenumber='"+this.getTargetuser().getphonenumber()+"' where ID="+this.getTargetuser().getid());
		dc.commit("update user set sex="+this.getTargetuser().getsex()+" where ID="+this.getTargetuser().getid());
		dc.commit("update user set realname='"+this.getTargetuser().getrealname()+"' where ID="+this.getTargetuser().getid());
		if(this.getTargetuser().isAdmin())
		dc.commit("update user set isadmin=1 where ID="+this.getTargetuser().getid());
		else dc.commit("update user set isadmin=0 where ID="+this.getTargetuser().getid());
	}

}
